﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace TileMaker
{
    public static class UniqueID
    {
        public static string GetNewID(int seed)
        {
            Random rd = new Random(seed);
            MD5 md5 = MD5.Create();
            byte[] input = Encoding.ASCII.GetBytes(rd.Next().ToString());
            byte[] hash = md5.ComputeHash(input);

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
                sb.Append(hash[i].ToString("x2"));

            int range = rd.Next(hash.Length - 8);
            return sb.ToString().Substring(range, 8);
        }

        public static string GetNewID()
        {
            return GetNewID((new Random()).Next());
        }
    }
}
